<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="txt">

    <button id="btn">点击添加</button>
    <p></p>
    <script>
        var arr = [1, 2, 3, 4, 5, 6]
        var hh = document.getElementsByTagName('p')
        hh[0].innerHTML = arr

        btn.onclick = function () {
            arr.push(txt.value)
            arr.sort(function (a, b) {
                return a - b
            })
            // return arr
            hh[0].innerHTML = arr
            txt.value = ''
        }
    </script>
</body>

</html>